package com.yubest.shiro.controller;

import com.yubest.shiro.bean.Response;
import com.yubest.shiro.bean.UserInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequiresPermissions(value = {"testx"})
    @GetMapping(value = "/testx")
    public Response<Void> test1() {
        return Response.ok(null);
    }

    @RequiresPermissions(value = {"test2"})
    @GetMapping(value = "/test2")
    public Response<Void> test2() {
        return Response.ok(null);
    }

    @RequiresPermissions(value = {"test3"})
    @GetMapping(value = "/test3")
    public Response<Void> test3() {
        return Response.ok(null);
    }

    @RequiresPermissions(value = {"info"})
    @GetMapping(value = "/info")
    public Response<UserInfo> info() {
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getPrincipal();
        return Response.ok(userInfo);
    }

}
